package com.job.admin.user.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.stream.StreamReader;
import com.job.admin.model.user.pojo.AdminUser;
import com.job.admin.user.service.UserService;
import com.job.client.common.result.AppHttpCode;
import com.job.client.common.result.ResponseResult;
import com.job.client.common.utils.DateTimeUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/admin/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public ResponseResult login(@RequestBody AdminUser adminUser){
        return userService.login(adminUser);
    }

    @GetMapping("/all/page")
    @ApiOperation("分页查询用户信息")
    public ResponseResult getUserInfoByPage(@RequestParam Integer page,@RequestParam Integer size){
        return userService.getUserInfoByPage(page,size);
    }

    @GetMapping("/all")
    @ApiOperation("获得全部用户信息")
    public ResponseResult getAllUserInfo(){
        return userService.getAllUserInfo();
    }

    @GetMapping("")

    @PostMapping("/check/userNumber")
    @ApiOperation("检查用户工号是否重复")
    public ResponseResult checkUserNumber(@RequestParam String userNumber){
        return userService.checkUserNumber(userNumber);
    }

    @PostMapping("/create")
    @ApiOperation("创建用户")
    public ResponseResult createUser(@RequestBody AdminUser adminUser){
        adminUser.setCreateTime(DateTimeUtils.createNowTime());
        adminUser.setUpdateTime(DateTimeUtils.createNowTime());
        return userService.createUser(adminUser);
    }

    @PostMapping("/update")
    @ApiOperation("修改用户")
    public ResponseResult updateUser(@RequestBody AdminUser adminUser){
        return userService.updateUser(adminUser);
    }

    @GetMapping("/delete")
    @ApiOperation("删除用户")
    public ResponseResult deleteUser(@RequestParam String userId){
        return userService.deleteUser(userId);
    }

    @PostMapping("/delete/bluk")
    @ApiOperation("批量删除用户")
    public ResponseResult deleteBluk(@RequestBody List<String> userIds){
        return userService.deleteBluk(userIds);
    }

    @GetMapping("/delete/permission")
    @ApiOperation("删除用户权限")
    public ResponseResult deletePermission(@RequestParam String userId,@RequestParam String permissionId){
        return userService.deletePermission(userId,permissionId);
    }

    @PostMapping("/update/permission")
    @ApiOperation("修改用户权限")
    public ResponseResult updatePermission(@RequestParam String userId,@RequestBody List<String> permissionList){
        return userService.updatePermission(userId,permissionList);
    }

}
